<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@taglib prefix="fm" uri="http://www.springframework.org/tags/form" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<%@include file="../header.jsp" %>
<script src="statics/calendar/WdatePicker.js"></script>
<script>
	$(function(){
		bindRole();
		bindEvent();
	})
	
	function bindRole(){
		$.get("listRole",function(msg){
			var str = "";
			$(msg).each(function(i){
				var r = msg[i]
				str += "<option value='"+r.id+"'>"
				str += r.rolename
				str += "</option>"
			})
			$("#userRole").append(str)
		},"json");
	}
	
	function bindEvent(){
		$("#add").click(function(){
			//数据校验
			
			//表单提交
			document.forms[0].submit();
		})
		
		//异步校验用户编号的唯一性
		$("#userCode").blur(function(){
			var usercode = $(this).val();
			if(usercode == null || usercode == ""){
				$(this).next("font").html("请输入用户编码")
			}else{
				//异步校验
				$.post("checkUsercode",{"usercode" : usercode},function(msg){
					if(msg.count == 0){
						$("#userCode").next("font").html("用户编码可以使用").css("color","green")
					}else{
						$("#userCode").next("font").html("用户编码不可以使用").css("color","red")
					}
				
				},"json")
			}
		})
	}
</script>

<c:if test="${requestScope.insertflag==0 }">
	<script>
		alert("添加失败")
	</script>
</c:if>
<c:if test="${requestScope.insertflag==1 }">
	<script>
		alert("添加成功")
		//跳转到列表页
		window.location = "toUserList"
	</script>
</c:if>

<div class="right">
        <div class="location">
            <strong>你现在所在的位置是:</strong>
            <span>用户管理页面 >> 用户添加页面</span>
        </div>
        <div class="providerAdd">
            <form id="userForm" name="userForm" method="post" action="insertUser" enctype="multipart/form-data">
                <!--div的class 为error是验证错误，ok是验证成功-->
                <div>
                    <label for="userCode">用户编码：</label>
                    <input type="text" name="usercode" id="userCode" value=""> 
					
					<!-- 放置提示信息 -->
					<font color="red"><fm:errors path="usercode"></fm:errors></font>
                </div>
                <div>
                    <label for="userName">用户名称：</label>
                    <input type="text" name="username" id="userName" value=""> 
					<font color="red"></font>
                </div>
                <div>
                    <label for="userPassword">用户密码：</label>
                    <input type="password" name="userpassword" id="userPassword" value=""> 
					<font color="red"></font>
                </div>
                <div>
                    <label for="ruserPassword">确认密码：</label>
                    <input type="password" name="ruserPassword" id="ruserPassword" value=""> 
					<font color="red"></font>
                </div>
                <div>
                    <label >用户性别：</label>
					<select name="gender" id="gender">
					    <option value="0" selected="selected">男</option>
					    <option value="1">女</option>
					 </select>
                </div>
               <div>
                    <label for="birthday">出生日期：</label>
                    <input type="text" Class="Wdate" id="birthday" name="birthday" 
					readonly="readonly" onclick="WdatePicker();">
					<font color="red"></font>
                </div>
                <div>
                    <label for="phone">用户电话：</label>
                    <input type="text" name="phone" id="phone" value=""> 
					<font color="red"></font>
                </div>
                <div>
                    <label for="address">用户地址：</label>
                   <input name="address" id="address"  value="">
                </div>
                <div>
                    <label >用户角色：</label>
                    <!-- 列出所有的角色分类 -->
					<select name="userrole.id" id="userRole"></select>
	        		<font color="red"></font>
                </div>
            
                <div>
                    <label for="a_idPicPath">证件照：</label>
                   	<input type="file" name="cphoto" id="a_idPicPath"/>
                    <font color="red"></font>
                </div>
               <div>
     
                    <label for="a_workPicPath">工作证照片：</label>
                   	<input type="file" name="wphoto" id="a_workPicPath"/>
                    <font color="red"></font>
                </div> 
                <div class="providerAddBtn">
                    <input type="button" name="add" id="add" value="保存" >
					<input type="button" id="back" name="back" value="返回" >
                </div>
            </form>
        </div>
</div>
</section>
<%@include file="../foot.jsp" %>
